﻿#include <stdio.h>
#include "ppt.h"

void instructions(void);
void printflist(char * value);
void success(void);
void fail(char *value);
void error_1(void);
void error_2(void);
void insert_play(Handler star, char * value);
void dele_play(Handler star, char * value);
int main(void)
{
	
	int start = Create();
	char item[SIZE] = {0};//链表编号初始化
	instructions();//输出菜单提示文字
	puts("?");//叫你输入了
	int choice;//初始化菜单选项
	scanf_s("%d", &choice, 0);//输入菜单选项
	while (choice != 3)//当菜单选项不是3（结束时）
	{
		switch (choice)
		{
		case 1://（插入和新建链表）
			printf("%s", "enter a character or number :");//输出提示文字
			scanf_s("%s", item, SIZE);//获取菜单编号
			//printf("%s\n", item);
			insert_play(start, item);
			break;
		case 2://（删除函数）
			printf("%s", "enter character or number to be deleted :");
			scanf_s("\n%s", item, SIZE);//获取要删除的链表编号
			dele_play(start, item);
			break;
		default://输入declude(1,2,3)的字符时
			puts("invalid choice.\n");
			instructions();//输出提示菜单
			break;
		}

		puts("?");//叫你输入
		scanf_s("%d", &choice, 1);//回到循环选项

	}
	puts("end of run");//不玩了
	getchar();//停留
	return 0;
}

void instructions(void)//输出提示菜单函数
{
	puts("enter your choice\n\
		 		 1 to insert an element into the list.\n\
				 2 to delete an element from the list .\n\
				 3 to end\n\
								 		");//1是新增和插入链表，2是删除链表,3是结束程序
}

void printflist(char * value)
{
	if (value != "")
	{
		printf("%s-->", value);//指引文字
	}
	else
	{
		printf("%s", "NULL");//结束文字
	}
}

void success(void)
{
	printf("%s\n", "this line is");//提示文字
}

void fail(char *value)
{
	printf("%s\n%s\n%s\n", value, "     the word cannot be found !", "this line is");//找不到相关选项
}

void error_1(void)
{
	printf("%s\n", "have not enough space !");//没有足够空间
}
void error_2(void)
{
	printf("%s\n", "the line is empty!");//空列表
}
void insert_play(Handler star, char * value)//外露
{
	//printf("%s\n", value);
	switch (insert(star, value))
	{
	case _Success_:
		success();
		Foreach(star, printflist);
		puts("NULL");
		break;
	case _fail_:
		fail(value);
		Foreach(star, printflist);
		puts("NULL");
		break;
	case _error_:
		error_1();
		break;
	}

}
void dele_play(Handler star, char * value)//外露
{
	switch (dele(star, value))
	{
	case _Success_:
		success();
		Foreach(star, printflist);
		puts("NULL");
		break;
	case _fail_:
		fail(value);
		Foreach(star, printflist);
		puts("NULL");
		break;
	case _error_:
		error_2();
		break;
	}

}

